<?php

class Tail_board extends CActiveRecord
{	
	/**
	 * The followings are the available columns in table 'Trucks':
	 * @var integer $id
	 * @var string $plate_no
	 * @var string $property_owner
	 * @var string $reg_date
	 * @var string $reg_no
	 * @var string $type
	 * @var string $brand
	 * @var string $type_id
	 * @var string $body_color
	 * @var string $frame_no
	 * @var string $scrap_date
	 * @var string $engine_no
	 * @var string $engine_type_id
	 * @var integer $fuel_type
	 * @var string $displacement_power
	 * @var string $manufacturer
	 * @var string $steering_type
	 * @var string $tire_distance
	 * @var integer $tire_num
	 * @var string $tire_format
	 * @var integer $leaf_spring_num
	 * @var string $wheelbase
	 * @var string $wheel_distince
	 * @var string $gabarite
	 * @var string $container_immer_dimensions
	 * @var integer $origin
	 * @var double $total_weight
	 * @var double $rated_loading_weight
	 * @var integer $rated_passenger_capacity
	 * @var double $total_traction_weight
	 * @var integer $passenger_capacity_of_cap
	 * @var string $use_naure
	 * @var string $obtain_way
	 * @var string $manufacture_date
	 * @var double $depreciation
	 * @var double $total_cost
	 * @var integer $state
	 * @var string $create_time
	 */
	
	public $truck_plate_no;
	public $type;
	
	private $tireNumConfig=array('start'=>4,'end'=>20);//轮胎数量
	
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'trucks';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('plate_no','length','min'=>7),
			array('property_owner','length','max'=>100),
			array('reg_no','length','max'=>18),
			array('type','length','max'=>20),
			array('brand','length','max'=>10),
			array('type_id','length','max'=>30),
			array('body_color','length','max'=>10),
			array('frame_no','length','max'=>30),
			array('engine_no','length','max'=>18),
			array('engine_type_id','length','max'=>20),
			array('displacement_power','length','max'=>20),
			array('manufacturer','length','max'=>100),
			array('steering_type','length','max'=>10),
			array('tire_distance','length','max'=>10),
			array('tire_format','length','max'=>10),
			array('wheelbase','length','max'=>10),
			array('wheel_distince','length','max'=>10),
			array('gabarite','length','max'=>20),
			array('container_immer_dimensions','length','max'=>20),
			array('use_naure','length','max'=>20),
			array('obtain_way','length','max'=>20),
			array('fuel_type, tire_num, leaf_spring_num, origin, rated_passenger_capacity, passenger_capacity_of_cap,
			 state', 'numerical', 'integerOnly'=>true),
			array(' total_weight,rated_loading_weight, total_traction_weight, depreciation, total_cost', 'numerical'),
			array('property_owner,reg_date,reg_no,type,brand,type_id,body_color,frame_no,scrap_date,
			fuel_type,manufacturer,steering_type,tire_distance,tire_num,
			tire_format,leaf_spring_num,wheelbase,wheel_distince,gabarite,container_immer_dimensions,origin,total_weight,
			rated_loading_weight,use_naure,
			obtain_way,manufacture_date,depreciation,total_cost,state,create_time', 'required'),
			array('reg_date,scrap_date,manufacture_date', 'type','type'=>'date','message'=>'{attribute} 必须为日期型(年-月-日)'),
			array('total_traction_weight, rated_loading_weight, total_weight', 'match' ,'pattern' => '/^\d{1,6}(\.\d{1,2})?$/','message'=>'{attribute} 整数位最多6位，小数位2位'),
			array('total_cost,depreciation', 'match' ,'pattern' => '/^\d{1,16}(\.\d{1,2})?$/','message'=>'{attribute} 整数位最多16位，小数位2位'),
		);
	}

	/**
	 * Prepares attributes before performing validation.
	 */
	protected function beforeValidate($on)//在验证之前将无需用户输入的字段写入
	{
		if($this->isNewRecord){
			$this->state=0;
			$this->create_time=date('Y-m-d G:i:s');
			$this->kind=1;
		}
		return true;
	}
	
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}
	
	public function getTireNumOptions(){
		$arr=array();
		for($i=$this->tireNumConfig['start'];$i<=$this->tireNumConfig['end'];$i++){
			$arr["$i"]="{$i}个";
		}
		return $arr;	
	}
	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '索引号',
			'kind' => '车辆/尾板',
			'fk_truck_id' => '所属车头Id',
			'fk_type_id' => '车辆类型对应车型id',
			'plate_no' => '尾板牌号',
			'truck_plate_no'=>'所属车辆牌号',
			'property_owner' => '产权登记单位',
			'reg_date' => '登记日期',
			'reg_no' => '登记编号',
			'type' => '车辆类型',
			'brand' => '车辆品牌',
			'type_id' => '车辆型号',
			'body_color' => '车身颜色',
			'frame_no' => '车架号',
			'scrap_date' => '强制报废日期',
			'engine_no' => '发动机号',
			'engine_type_id' => '发动机型号',
			'fuel_type' => '燃料种类',
			'displacement_power' => '排量功率',
			'manufacturer' => '制造商名称',
			'steering_type' => '转向形式',
			'tire_distance' => '轮距',
			'tire_num' => '轮胎数',
			'tire_format' => '轮胎规格',
			'leaf_spring_num' => '钢板弹簧数(个)',
			'wheelbase' => '轴距',
			'wheel_distince' => '轴数',
			'gabarite' => '外廓尺寸',
			'container_immer_dimensions' => '货箱内部尺寸',
			'origin' => '国产/进口',
			'total_weight' => '总质量(吨)',
			'rated_loading_weight' => '核定载重质量(吨)',
			'rated_passenger_capacity' => '核定载客数量(人)',
			'total_traction_weight' => '准牵引总质量(吨)',
			'passenger_capacity_of_cap' => '驾驶室载客(人)',
			'use_naure' => '使用性质',
			'obtain_way' => '车辆获得方式',
			'manufacture_date' => '出厂日期',
			'depreciation' => '月折旧额(元)',
			'total_cost' => '购置总额(元)',
			'state' => '状态',
			'create_time' => '创建日期',
		);
	}
	
	public function safeAttributes(){
		$params=parent::safeAttributes();
		$params[]='truck_plate_no';
		$params[]='type';
		return $params;
	}
}